package com.jcl.recruit.resume.logic;

import com.jcl.core.utils.CollectionUtils;
import com.jcl.recruit.resume.dao.ResumeEvaluateDao;
import com.jcl.recruit.resume.model.ResumeEvaluate;
import com.jcl.recruit.user.logic.UserLogic;
import com.jcl.recruit.user.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ResumeEvaluateLogic

 * @Author yyliu
 * @Date 2018/9/17 10:00
 * @Version 1.0
 **/
@Component
public class ResumeEvaluateLogic {

    @Autowired
    private ResumeEvaluateDao resumeEvaluateDao;

    @Autowired
    private UserLogic userLogic;

    public List<ResumeEvaluate> contractDetailList(String corpCode, List<ResumeEvaluate> evaluates) {
        if (CollectionUtils.isNotEmpty(evaluates)) {
            List<Integer> userIds = new ArrayList<>();
            for (ResumeEvaluate evaluate : evaluates) {
                if (!userIds.contains(evaluate.getAddUser()) && null != evaluate.getAddUser()) {
                    userIds.add(evaluate.getAddUser());
                }
            }

            Map<Integer, User> userMap = userLogic.getUserMap(corpCode, userIds);

            for (ResumeEvaluate evaluate : evaluates) {
                User user = userMap.get(evaluate.getAddUser());
                if (null != user) {
                    evaluate.setAddUserName(user.getRealname());
                }
            }
        }
        return evaluates;
    }

    public List<ResumeEvaluate> findList(String corpCode, int resumeId) {
        return resumeEvaluateDao.findList(corpCode, resumeId);
    }

    public int add(ResumeEvaluate resumeEvaluate) {
        return resumeEvaluateDao.add(resumeEvaluate);
    }


}
